<template>
  <div>
    <nav-bar title="访客管理"></nav-bar>
    <div class="maxinBox">
      <van-cell is-link title="处理状态" :value="statusName" @click="showStatus = true" />
      <van-action-sheet v-model="showStatus" :actions="statusList" @select="onSelectStatus" />
      <van-row class="backgroundfff">
        <van-col :span="22">
          <van-cell title="访问时间" @click="onVisitorTime" :value="visitorTime" />
        </van-col>
        <van-col :span="2" v-if="visitorTime">
          <van-icon name="delete" style="font-size: 1.25rem;line-height: 2.75rem;" @click="delTime" />
        </van-col>
      </van-row>
      <van-popup v-model="showVisitorTimeTime" position="bottom" style="height: 40%">
        <van-datetime-picker
          @confirm="visitorConfirm"
          @cancel="showVisitorTimeTime = false"
          type="date"
          :title="$t('dashbord.workTypeInformation.chooseDate')"
          :min-date="minDate"
          :max-date="maxDate"
        />
      </van-popup>
      <div>
        <van-row class="visitorBox backgroundfff marginTop5" style="padding: 0.9375rem;" v-for="(item, index) in visitorList" :key="index" @click="visitorDetails(item)">
          <van-col :span="7">
            <img style="width: 90%" :src="item.headUrl" alt="">
          </van-col>
          <van-col :span="11" class="fontSize14">
            <div>{{item.name}}</div>
            <div>{{item.mobile}}</div>
            <div>{{item.visitStartTime | formatDate}}</div>
            <div>{{item.reasonText}}</div>
          </van-col>
          <van-col :span="6">
            <img v-if="item.status === 1" src="../../../assets/images/agree.png" alt="">
            <img v-if="item.status === 4" src="../../../assets/images/filure.png" alt="">
            <img v-if="item.status === 3" src="../../../assets/images/processed.png" alt="">
            <img v-if="item.status === 2" src="../../../assets/images/refused.png" alt="">
          </van-col>
        </van-row>
      </div>
    </div>

  </div>
</template>

<script>
  import moment from 'moment'
  import visitorAPI from '../../../api/workAPI/visitorsAPI.js'
  import image from '../../../assets/images/logo.png'
  export default {
    data() {
      return {
        showVisitorTimeTime: false,
        visitorTime: '',
        minDate: new Date(),
        maxDate: new Date(2025, 10, 1),
        statusName: '',
        status: '',
        showStatus: false,
        status: 0,
        statusList: [
          { name: '全部', value: 0 },
          { name: '已同意', value: 1 },
          { name: '已拒绝', value: 2 },
          { name: '待处理', value: 3 },
          { name: '已失效', value: 4 },
        ],
        visitorList: []
      }
    },
    methods: {
      onVisitorTime() {
        this.showVisitorTimeTime = true
      },
      // 进场日期选择确定按钮
      visitorConfirm(val) {
       this.visitorTime = moment(val).format('YYYY-MM-DD')
       this.showVisitorTimeTime = false
       this.getVisitor()
      },
      onSelectStatus(item) {
        this.showStatus = false;
        this.status = item.value
        this.statusName = item.name
        this.getVisitor()
      },
      getVisitor() {
        let status
        if (this.status === 0) {
          status = ''
        } else {
          status = this.status
        }
        let data = {
          status: status,
          visitDate: this.visitorTime,
          projectId: 1
        }
        visitorAPI.getVisitorList(data).then(res => {
          this.visitorList = res
        })
      },
      delTime() {
        this.visitorTime = null
        this.getVisitor()
      },
      visitorDetails(item) {
        this.$router.push({
          name: 'VisitorDetails',
          params:{
            data: item
          }
        })
      }
    },
    mounted() {
      this.getVisitor()
    }
  }
</script>

<style scoped lang="scss">
  .visitorBox{
    border-bottom: $border;
    .van-col--6{
      height: 5.125rem;
      line-height: 5.3125rem;
      img{
        max-height: 3.125rem;
        display: inline-block;
        vertical-align: middle;
      }
    }
  }
</style>
